我的fzf配置
# cd
fzd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune -o -type d -print 2> /dev/null |\
fzf --preview-window=hidden +m) &&
cd "$dir"
}
bash
# job kill
fzkill() {
local pid
local pinfo=$(ps -ef | grep -P "^$USER" | fzf -m --preview-window=hidden)
local pid=$(echo "$pinfo" | perl -lane 'print $F[1]')
if [ "x$pid" != "x" ]
then
gst_warn "
Kill these processes? [y/N]
------------------------------
$pinfo
------------------------------
"
local cfm="N"
read cfm
if [[ "$cfm" == "y" ]];then
echo "$pid" | xargs kill -${1:-9}
fi
fi
}
bash
# module
fzmd(){
local avalmds
if [[ -n "$MODULESHOME" ]];then
avalmd=$(module aval 2>&1 | perl -lane '$,="\n"; print @F unless /^-/ or /^\s*$/' |\
fzf -m --preview-window=hidden | perl -pe 's/\n/ / unless eof')
if [ "x$avalmd" != "x" ];then
gst_rcd "load selected modules: $avalmd "
module load $avalmd
fi
fi
}
bash
# bookmarks
unalias adb 2>/dev/null
unalias cdb 2>/dev/null
export GST_BOOKMARK="$GSTCFG/bookmark.cfg"
adb(){
# add current path to pathdb
local cur_path=$PWD
touch $GST_BOOKMARK
cat $GST_BOOKMARK | grep -P "^${cur_path}$" >/dev/null
if [ $? -ne 0 ];then
echo "$cur_path" >> $GST_BOOKMARK
echo -e "\033[36m[$(date +'%y-%m-%d %H:%M')]\033[0m Added pwd to GST_BOOKMARK"
else
echo -e "\033[35m[WARNING]\033[0m --> Already in bookmark" >&2
fi
}
cdb(){
local dest_dir=$(cat $GST_BOOKMARK | sed 's/^#.*//g; /^\s*$/d' | fzf --preview-window=hidden)
if [[ $dest_dir != '' ]];then
cd "$dest_dir" && ls
fi
}
alias vdb="vim $GST_BOOKMARK"
bash